import { apiGetOrderShareByOrderId } from '../../api/index'
Page({
  /**
   * 页面的初始数据
   */
  data: {
    id: '',
    goodData: [],
    makeMoney: 0,
    isShow: false,
    shareComm: {}
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad (options) {
    this.data.goodData = JSON.stringify(options)
    this.data.makeMoney = options.money
    this.data.id = options.id
    let isShow
    if (options.help_type) {
      isShow = false
      this.helpType = (options.help_type - 0)
      console.log(this.helpType)
    } else {
      isShow = true
      this.init()
    }
    this.setData({
      navHeight: getApp().globalData.navHeight * 2,
      helpType: options.help_type ? options.help_type - 0 : '',
      isShow
    })
  },
  init () {
    // 获取佣金
    apiGetOrderShareByOrderId({ order_id: this.data.id }).then(
      res => {
        console.log(res)
        this.setData({
          shareComm: res.data
        })
      }
    )
  },
  orderDetail () {
    if (this.helpType === 1) {
      wx.navigateTo({
        url: `../order-detail/order-detail?id=${this.data.id}&help_type=1`
      })
    } else {
      wx.navigateTo({
        url: `../order-detail/order-detail?id=${this.data.id}`
      })
    }
  },
  goHome () {
    wx.switchTab({
      url: '../shopping/shopping'
    })
  },
  toShare () {
    wx.navigateTo({
      url: `../share/share?order_id=${this.data.id}`
    })
  },
  // 接力
  toRelay () {
    wx.navigateTo({
      url: `../relay/index?id=${this.data.shareComm.order_share_id}&type=1`
    })
  },
  // 接力佣金
  toRelayDetail () {
    wx.navigateTo({
      url: `../bring-out/bring-out?relay_type=1`
    })
  },
  isClose () {
    this.setData({
      isShow: false
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide () {

  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload () {
    wx.switchTab({
      url: '/pages/shopping/shopping'
    })
  }
})
